package com.rlyy.basic.config;

import com.rlyy.basic.resolver.valid.check.ValidatorFailFastFactory;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;

import javax.validation.Validation;
import javax.validation.ValidatorFactory;

/**
 * 配置快速失败校验器
 *
 * @author yuanqinglong
 * @since 2021/4/16 14:04
 */
@Configuration
public class ValidatorConfig extends LocalValidatorFactoryBean {


    /**
     * 注册快速失败校验器
     *
     * @return ValidatorFailFastFactory
     */
    @Bean
    public ValidatorFailFastFactory validatorFailFast() {
        ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class)
                .configure()
                .addProperty("hibernate.validator.fail_fast", "true")
                .buildValidatorFactory();
        return new ValidatorFailFastFactory(validatorFactory);
    }

}
